<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" :title="title"></uni-navbar></view>

		<view class="search-view"><u-search class="search-input" shape="square" bg-color="#fff" @search="search" @custom="search"></u-search></view>

		<u-tabs class="btm-tabs" :list="tabsList" :current="tabsCurrent" @change="tabsChange"></u-tabs>

		<view class="filter-inner">
			<view class="filter-btn" :class="info.nodeStatus == '2' ? 'active' : ''" @click="filter('2')">所有</view>
			<view class="filter-btn" :class="info.nodeStatus != '2' ? 'active' : ''" @click="filter('')">我的</view>
		</view>

		<view class="list-box" :style="{ background: loading == 'nodata' ? 'none' : '#fff' }">
			<view class="list-info_02" v-for="(item, index) of infoList" :key="item.id" @click="navTo(item)">
				<view class="left">
					<view class="info-title">{{ item.title }}</view>
					<view class="info-btm">
						<view class="name clamp">{{ item.createByName }}</view>
						<text class="line"></text>
						<view class="time">{{ item.createTime }}</view>
						<view class="status" :style="'color:' + colorMap[item.nodeStatus]">{{ item.nodeStatusName }}</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="loading" />
		</view>

		<view class="uploader-add" @click="addTo()"><u-icon name="plus" color="#fff" size="40"></u-icon></view>
		<u-back-top :scroll-top="scrollTop" top="200"></u-back-top>

		<view v-if="false && news && dict"></view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			scrollTop: 0,
			tabsCurrent: 0,
			tabsList: [
				{
					name: '戏曲',
					value: '4'
				},
				{
					name: '绘画',
					value: '3'
				},
				{
					name: '美文',
					value: '6'
				},
				{
					name: '代表事迹',
					value: '7'
				},
				{
					name: '书法',
					value: '2'
				},
				{
					name: '摄影',
					value: '1'
				},
				{
					name: '音乐',
					value: '5'
				}
			],
			colorMap: {
				1: '#0099ff',
				2: '#e5231a',
				3: '#19be6b'
			},
			title: '代表风采',
			infoList: [],

			info: {
				nodeStatus: '2',
				status: 1,
				type: '4',
				title: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad(option) {
		this.loadLogin();

		this.loadData();
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.sysUser) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add' && this.loading == 'nomore') {
				return false;
			}

			this.loading = 'loading';
			if (type != 'add') {
				this.pageNum = 1;
			}
			if (this.info.classification == '-1') {
				this.info.classification = '';
			}
			let url = '/wyfc/myList';
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				currentUserId: this.userId,
				wyfc: this.info
			};

			this.$request(url, data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.infoList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.infoList = this.infoList.concat(res.data.records);
				this.loaded = true;
				if (this.infoList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		tabsChange(index) {
			this.tabsCurrent = index;
			this.type(this.tabsList[index].value);
		},
		search(e) {
			this.info.title = e;
			this.loadData('refresh');
		},
		type(e) {
			this.info.type = e;
			this.loadData('refresh');
		},
		filter(e) {
			this.info.nodeStatus = e;
			this.loadData('refresh');
		},
		addTo() {
			uni.navigateTo({
				url: '/pagesA/avenger/add'
			});
		},
		navTo(item) {
			uni.navigateTo({
				url: '/pagesA/avenger/detail?id=' + item.id
			});
		}
	}
};
</script>

<style lang="scss">
.list-box {
	padding: 0 30rpx;
	background-color: #fff;
}

.filter-inner {
	margin-bottom: 0;
	border-bottom: 20rpx solid #f5f7fa;
	background-color: #fff;
}

.list-info_02 {
	.time {
		flex-shrink: 0;
	}

	.right {
		overflow: hidden;

		image {
			width: 236rpx;
			height: 148rpx;
		}
	}
}
</style>
